/**
  * @file		helper.c
  * @author		Supachai Vorapojpisut
  * @version	V1.0.0
  * @date		October 13, 2013
  * @brief		Collection of helper functions 
  */

/* Includes ------------------------------------------------------------------*/
#include "helper.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
volatile uint32_t Tick = 0;
volatile int32_t ITM_RxBuffer = ITM_RXBUFFER_EMPTY;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/**
  * @brief		Handler for SysTick exception - update Tick
  * @param		None
  * @retval		None
  */
void SysTick_Handler()
{
	Tick++;
}
 

/**
  * @brief		Pauses the program for the amount of time (in miliseconds) specified as parameter.
  * @param		ms			Number of milliseconds to pause. 
  * @retval		None
  * @remark		Require the configuration of SysTick at 1 millisecond
  */
void delay(uint32_t ms)
{
	uint32_t start = Tick;
	while ((Tick - start) < ms);
}


/**
  * @brief		Low-level character input function - using ITM
  * @param		f			not used.
  * @retval		None
  */
int fgetc(FILE *f)
{
	return ITM_ReceiveChar();
}


/**
  * @brief		Low-level character output function - using ITM
  * @param		ch			character to be printed.
  * @param		f			not used
  * @retval		Printed character.
  */
int fputc(int ch, FILE *f)
{
	ITM_SendChar(ch);
	return ch;
}


/**
  * @brief		?
  * @param		None
  * @retval		None
  */
